package com.kangaroo.myhome.controller;

import javax.servlet.http.HttpServletRequest;

import com.kangaroo.myhome.service.impl.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.kangaroo.myhome.model.TSysMenu;
import com.kangaroo.myhome.service.impl.SubWayService;
import com.kangaroo.myhome.vo.ResponseModel;

/**
 * @Description: 功能描述: //
 * @author: kangaroo
 * @date: 2020/7/31 0:02
 */
@RestController
@RequestMapping("menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    // @PreAuthorize("hasAuthority('sys:user:view')")
    @GetMapping(value = "/findAll")
    public ResponseModel findAll(HttpServletRequest request) {
        String name = request.getParameter("name");
        String pageS = request.getParameter("page");
        String rowsS = request.getParameter("rows");
        int page = Integer.parseInt(pageS);
        int rows = Integer.parseInt(rowsS);
        return menuService.findAll(name, page, rows);
    }

    // @PreAuthorize("hasAuthority('sys:user:edit')")
    @PostMapping(value = "/edit")
    public ResponseModel edit(@RequestBody TSysMenu tSysMenu) {
        return menuService.edit(tSysMenu);
    }

    // @PreAuthorize("hasAuthority('sys:user:edit')")
    @GetMapping(value = "/view")
    public ResponseModel view(HttpServletRequest request) {
        ResponseModel model = new ResponseModel();
        String id = request.getParameter("id");

        TSysMenu tSysMenu = new TSysMenu();
        tSysMenu.setId(id);
        TSysMenu user = menuService.view(tSysMenu);
        model.setCode(200);
        model.setMessage("获取成功");
        model.setData(user);
        return model;
    }

    // @PreAuthorize("hasAuthority('sys:user:delete')")
    @PostMapping(value = "/delete")
    public ResponseModel delete(HttpServletRequest request) {
        String id = request.getParameter("id");
        TSysMenu tSysMenu = new TSysMenu();
        tSysMenu.setId(id);
        menuService.delete(tSysMenu);
        ResponseModel model = new ResponseModel();
        model.setCode(200);
        model.setMessage("获取成功");
        return model;
    }

}